/*
 * PCMDataBlock.cpp
 *
 *  Created on: Nov 24, 2011
 *      Author: shaohong
 */

#include "PCM_Data_Block.h"
#include "NmpsException.h"

#include <string.h>
#include <stdlib.h>
namespace nmps {

	PCM_Data_Block::PCM_Data_Block(int size) {
		dataSize = size;
		pcmData = (char *)malloc(size);
	}

	PCM_Data_Block::~PCM_Data_Block() {
		free(pcmData);
	}

	int PCM_Data_Block::getDataSize() const {
		return dataSize;
	}

	char * PCM_Data_Block::getPcmData() {
		return pcmData;
	}

	void PCM_Data_Block::setPcmData(unsigned char * pcmdata) {
		memcpy((void *)pcmData, (void *)pcmdata, (unsigned long int)dataSize);
	}

	void PCM_Data_Block::getPcmData(int startPos, int endPos, char * targetMem){
		if (startPos < 0) {
			throw  NmpsException( "startPos is invalid" );
		}

		if (endPos > getDataSize()) {
			throw  NmpsException( "endPos is invalid" );
		}

		memcpy((void *)targetMem, (void *) (getPcmData() + startPos), (endPos - startPos));

	}

} /* namespace nmps */
